import { createVNode } from 'vue'
import { notification, Modal } from 'ant-design-vue';
import { QuestionCircleOutlined, WarningOutlined, CloseCircleOutlined, CheckCircleOutlined, InfoCircleOutlined } from '@ant-design/icons-vue';



/**
 * 弹框图标  <warning-outlined />   <question-circle-outlined />  <exclamation-circle-outlined /> <check-circle-outlined />  <close-circle-outlined />  <info-circle-outlined />
 */
export enum MessageBoxIcon {

    /**
     * 成功 一个圆圈里面一个勾图标
     */
    OK,

    /**
     * 信息框 
     */
    Info,

    /**
     * 询问 一个圆圈里面有一个问号图标
     */
    Question,

    /**
     * 警告 
     */
    Warning,
    /**
     * 关闭 一个圆圈里面有一个×符号
     */
    Close
}


/**
 * 消息框
 */
export class MessageBox {

    /**
     * 获取图标
     * @param icon 
     * @returns 
     */
    private static getIcon(icon: MessageBoxIcon) {

        switch (icon) {
            case MessageBoxIcon.OK:
                return CheckCircleOutlined;
            case MessageBoxIcon.Question:
                return QuestionCircleOutlined;
            case MessageBoxIcon.Warning:
                return WarningOutlined;
            case MessageBoxIcon.Close:
                return CloseCircleOutlined;
            case MessageBoxIcon.Info:
                return InfoCircleOutlined;
        }
    }

    /**
     * 询问框
     * @param content 内容
     * @param title 标题
     * @returns boolean
     */
    static async confirm(content: string = "确定要删除吗?", title: string = "提示"): Promise<boolean> {
        return new Promise((resolve) => {
            Modal.confirm({
                title: title,
                icon: createVNode(QuestionCircleOutlined),
                content: content,
                onOk() {
                    resolve(true);
                },
                onCancel() {
                    resolve(false);
                }
            })
        });
    }

    /**
     * 信息框
     * @param content 信息内容
     * @param title  标题
     * @returns boolean
     */
    static async alert(content: string, title: string = "信息", icon: MessageBoxIcon = MessageBoxIcon.Info): Promise<boolean> {
        return new Promise((resolve) => {
            Modal.info({
                title: title,
                content: content,
                icon: createVNode(this.getIcon(icon)),
                onOk() {
                    resolve(true);
                },
                onCancel() {
                    resolve(false)
                }
            })
        })
    }

    /**
     * 是否返回到列表页面
     * @param content 
     * @param title 
     * @returns boolean
     */
    static async goToListPage(content: string = "是否返回列表?", title: string = "提示"): Promise<boolean> {
        return await this.confirm(content, title);
    }


}